#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QWebEngineView>
#include <QWebEnginePage> // Add this line
#include <QUrl> // Add this line

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class WebView : public QWebEngineView // Add this class
{
    Q_OBJECT
public:
    explicit WebView(QWidget *parent = nullptr)
    {
        setAttribute(Qt::WA_DeleteOnClose);
        connect(this->page(), &QWebEnginePage::linkHovered, this, &WebView::slot_LinkHovered);
    }
    ~WebView() {}

protected:
    QWebEngineView* createWindow(QWebEnginePage::WebWindowType type) override
    {
        // Load the link address
        this->load(url_);
        return this;
    }

private slots:
    void slot_LinkHovered(const QString& url)
    {
        // Get the link address clicked in the view
        url_.setUrl(url);
    }

private:
    QUrl url_;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
